<?php

namespace app\api\controller;

use think\Controller;
use email\Smtp;
use think\Db;
use ipaddr\Ip;
use app\common\model\Complaint as ComplaintModel;

class Count extends Controller
{
    protected $complaint_model;
    protected $request_url;

    function _initialize(){
        parent::_initialize();
        $table_name = 'think_count_detail_'.TIME_PREFIX;
        $tables = Db::query("SHOW TABLES LIKE '{$table_name}'");
        if(!$tables){
            Db::query("CREATE TABLE {$table_name} LIKE think_count_detail");
        }
        $this->complaint_model = new ComplaintModel();
        $this->request_url = REQUEST_URL;
    }

    public function index(){
            $str = $_SERVER['HTTP_REFERER'];//域名
            $param = '/(http[s|]:\/\/[\s\S]+?)\//';
            preg_match($param,$str,$matches);
            $UriName = $matches[1];
            $reIP=$_SERVER["HTTP_X_FORWARDED_FOR"];//ip
            $url = IP_URL.$reIP;
            $data = http_url($url);
            $arr = explode('=',$data); 
            $abc = substr(trim($arr[1]),0,-1);
            $address = json_decode($abc,true);

            // var_dump(json_decode($abc,true));exit();
            // $data['data']['count_url'] = $UriName;
            // $data['data']['count_ip'] = $reIP;
            // $data['data']['visit_time'] = time();
            // unset($data['data']['ip']);
            $data = [
                'country'=>$address['country'],
                'province'=>$address['province'],
                'city'=>$address['city'],
                'count_url'=>$UriName,
                'count_ip'=>$reIP,
                'visit_time'=>time()
            ];
            

            // var_dump($tables);
            $result = Db::name('count_detail_'.TIME_PREFIX)->insertGetId($data);
            
            if(!$result){
                echo $result->getLastSql();
            }else{
                return json(['lase_Id'=>$result]);
            }
    }


    /**
     * 获取umuuid
     * @param $prefix string
     * @return string
     */
    function my_uuid($prefix   = '')
    {  
        $chars = md5(uniqid(mt_rand(), true));
        $uuid  = substr($chars,0,14) . '-';  
        $uuid .= substr($chars,14,13) . '-';  
        $uuid .= substr($chars,12,8) . '-';  
        $uuid .= substr($chars,20,6) . '-';  
        $uuid .= substr($chars,18,14);  
        return $prefix . $uuid;
    }  

    //新统计方法
    public function tj_stat2($id,$web_id,$code = ''){
        $country = '';
        $region = '';
        $city  = '';
        $isp = '';
        $wechat = '';
        if(array_key_exists('UM_distinctid',$_COOKIE)){
            $umuuid = $_COOKIE['UM_distinctid'];
        }elseif(!array_key_exists('umuuid',$_COOKIE)){
            $umuuid = $this->my_uuid();
            setcookie('umuuid',$umuuid,time()+3600*24*30);
        }else{
            $umuuid = $_COOKIE['umuuid'];
        }

        $is_adcount = Db::name('adcount')->where('id',$id)->find();
        if($is_adcount){
            $accept  = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
            $webInfo = getWebInfo($_SERVER['HTTP_USER_AGENT'],$accept);
            $reIP    = getIP();//ip
            $url     = IP_URL.$reIP;
            $data    = http_url($url);
            $ipInfo  = json_decode($data,true);
            if($ipInfo['code'] == 0){
                $country = isset($ipInfo['data']['country']) ? $ipInfo['data']['country'] : '';//国家
                $region = isset($ipInfo['data']['region']) ? $ipInfo['data']['region'] : '';//省份
                $city = isset($ipInfo['data']['city']) ? $ipInfo['data']['city'] : '';//城市
                $isp = isset($ipInfo['data']['isp']) ? $ipInfo['data']['isp'] : '';//运营商
            }
            $data = [ 
                'cid'        => $id,
                'wid'        => $web_id,
                'system'     => $webInfo['system'],
                'equip'      => $webInfo['equip'],
                'browser'    => $webInfo['browser'],
                'lang'       => $webInfo['lang'],
                'country'    => $country,
                'province'   => $region,
                'city'       => $city,
                'isp'        => $isp,
                'count_ip'   => $reIP,
                'umuuid'     => $umuuid,
                'response'   => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',//受访域名
                'visit_time' => time()
            ];
            //测试
            // $data = [
            //     'cid' => $id,
            //     'wid' => $web_id,
            //     'country'=>'中国',
            //     'province'=>'广东',
            //     'city'=>'广州',
            //     'count_ip'=>$reIP,
            //     'visit_time'=>time()
            // ];
            
            if(!empty($code)){
                $wechat = get_wechat_num_qrcode3($code);
            }
            // dump($wechat);exit();
            $result = Db::name('count_detail_'.TIME_PREFIX)->insertGetId($data);
            if(!$result){
                echo $result->getLastSql();
            }else{
                //$.get('https://{$_SERVER['HTTP_HOST']}/api/change_wx/get_wechat_num_qrcode2',{code:'{$code}'});
                return $wechat."var width = window.screen.availWidth;var height  = window.screen.availHeight;var fbl = width+'x'+height;var a=encodeURIComponent,ref = document.referrer; $(function(){ $.get('{$this->request_url}/api/count/ref_stat.html?id={$id}&r='+a(ref)+'&umuuid={$umuuid}&uid={$result}&rp='+fbl);}); _sns = new Object();_sns.push = function(stxlwx,kwd){var data_str = {'WeName':stxlwx,'id':{$result},'keyword':kwd};$.post('{$this->request_url}/api/count/copyAction', data_str);};_sns.comp = function(siteid,compid){var data_str = {'siteid':siteid,'ip':'{$reIP}','compid':compid};$.get('{$this->request_url}/api/count/cli_complaint', data_str);};";
            }
        }
    }

    public function ref_stat(){
        $data = $this->request->param();
        $where = [
            'id'=>['eq',$data['uid']],
            'cid'=>['eq',$data['id']],
        ];
        if(empty($data['r'])){
            Db::name('count_detail_'.TIME_PREFIX)->where($where)->update(['referer'=>'直接输入网址或书签','rp'=>$data['rp']]);
        }else{
            //获取关键词
            $keyword = $this->getKeyWord($data['r']);
            Db::name('count_detail_'.TIME_PREFIX)->where($where)->update(['referer'=>$data['r'],'origin_keyword'=>$keyword,'rp'=>$data['rp']]);
        }
    }

    //旧版获取关键词
    // public function KeyWord($ref) {
    //     if(!empty($ref)){
    //         $ref = urldecode(html_entity_decode($ref));
    //         $ref = urldecode($ref);
    //         $res = strpos($ref,'baidu.com');
    //         if($res){//百度搜索
    //             $pattern = "/&wo?r?d=([\s\S]+?)&/i";
    //             $status = preg_match_all($pattern,$ref,$matches,PREG_PATTERN_ORDER);
    //             if($status !== false){
    //                 if(empty($matches[1])){
    //                     $pattern = "/&wo?r?d=([\s\S]+?)&/i";
    //                     $status0 = preg_match_all($pattern,$ref,$matches,PREG_PATTERN_ORDER);
    //                     if($status0 !== false){
    //                         if(empty($matches[1])) return 'baidu/word联系后台开发人员';
    //                         return urldecode($matches[1][0]);
    //                     }else{
    //                         return '匹配有误';
    //                     }
    //                 }
    //             }else{
    //                 return '匹配有误';
    //             }
    //         }else if(strpos($ref,'so.com')){//360搜索
    //             $pattern = "/&q=([\s\S]+?)&/i";
    //             $status = preg_match_all($pattern,$ref,$matches);
    //             if($status !== false){
    //                 if(empty($matches[1])) return 'so/q&联系后台开发人员';
    //                 return urldecode($matches[1][0]);
    //             }else{
    //                 return '匹配有误';
    //             }
    //         }else if(strpos($ref,'sogou.com')){//搜狗
    //             if(strpos($ref,'&query=')){
    //                 $pattern = "/&query=([\s\S]+?)&/i";
    //                 $status0 = preg_match_all($pattern,$ref,$matches);
    //                 if($status0 !== false){
    //                     if(empty($matches[1])){
    //                         $pattern = "/&query=([\s\S]+)/i";
    //                         $status = preg_match_all($pattern,$ref,$matches);
    //                         if($status !== false){
    //                             if(empty($matches[1])) return 'sogou/query联系后台开发人员';
    //                             return urldecode($matches[1][0]);
    //                         }else{
    //                             return '匹配有误';
    //                         }
    //                     }else{
    //                         return urldecode($matches[1][0]);
    //                     }
    //                 }else{
    //                     return '匹配有误';
    //                 }
    //             }else if(strpos($ref,'&keyword=')){
    //                 $pattern = "/&keyword=([\s\S]+?)&/i";
    //                 $status = preg_match_all($pattern,$ref,$matches);
    //                 if($status0 !== false){
    //                     if(empty($matches[1])) return 'sogou/keyword&联系后台开发人员';
    //                     return urldecode($matches[1][0]);
    //                 }else{
    //                     return '匹配有误';
    //                 }
    //             }
    //         }else{
    //             return '未获取关键词';
    //         }
    //     }else{
    //         return '未获取关键词';
    //     }
    // }

    //新版获取关键词
    protected function getKeyWord($ref){
        $refArr = parse_url(html_entity_decode($ref));

        if(strpos($refArr['host'],'youxuan.baidu.com')){
            //百度优选gb2312编码
            return '百度优选暂无获取关键词';
        }
        
        $ref = urldecode(html_entity_decode($ref));
        $ref = urldecode($ref);

        if(strpos($refArr['host'],'baidu.com')){
            //百度
            $pattern = "/&wo?r?d=([\s\S]+?)&/i";
            $status = preg_match_all($pattern,$ref,$matches,PREG_PATTERN_ORDER);
            if($status !== false){
                if(empty($matches[1])) return 'baidu/word联系后台开发人员';
                return urldecode($matches[1][0]);
            }else{
                return '匹配有误';
            }

        }else if(strpos($refArr['host'],'so.com')){
            //360搜索
            $pattern = "/&q=([\s\S]+?)&/i";
            $status = preg_match_all($pattern,$ref,$matches);
            if($status !== false){
                if(empty($matches[1])) return 'so/q&联系后台开发人员';
                return urldecode($matches[1][0]);
            }else{
                return '匹配有误';
            }

        }else if(strpos($refArr['host'],'sogou.com')){
            //搜狗
            if(strpos($ref,'&query=')){
                $pattern = "/&query=([\s\S]+?)&/i";
                $status0 = preg_match_all($pattern,$ref,$matches);
                if($status0 !== false){
                    if(empty($matches[1])){
                        $pattern = "/&query=([\s\S]+)/i";
                        $status = preg_match_all($pattern,$ref,$matches);
                        if($status !== false){
                            if(empty($matches[1])) return 'sogou/query联系后台开发人员';
                            return urldecode($matches[1][0]);
                        }else{
                            return '匹配有误';
                        }
                    }else{
                        return urldecode($matches[1][0]);
                    }
                }else{
                    return '匹配有误';
                }
            }else if(strpos($ref,'&keyword=')){
                $pattern = "/&keyword=([\s\S]+?)&/i";
                $status = preg_match_all($pattern,$ref,$matches);
                if($status !== false){
                    if(empty($matches[1])){
                        $pattern = "/&keyword=([\S\s]+)/i";
                        $status = preg_match_all($pattern, $ref, $matches ); 
                        if($status !== false){
                            if(empty($matches[1])){
                                $pattern = "/\?(query=|keyword=)([\S\s]+?)&/i";
                                $status = preg_match_all($pattern, $ref, $matches ); 
                                if($status !== false){
                                    if(empty($matches[2])) return 'sogou/keyword&联系后台开发人员';
                                    return urldecode($matches[2][0]);
                                }else{
                                    return '匹配有误';
                                }
                            }else{
                                return urldecode($matches[1][0]);
                            }
                        }
                    }else{
                        return urldecode($matches[1][0]);
                    }
                }else{
                    return '匹配有误';
                }
            }
        }else{
            return '未获取关键词';
        }
    }

    //新统计方法
    public function tj_stat($id,$web_id,$code = ''){    
        $country = '';
        $region = '';
        $city  = '';
        $isp = '';
        $wechat = '';
        if(array_key_exists('UM_distinctid',$_COOKIE)){
            $umuuid = $_COOKIE['UM_distinctid'];
        }elseif(!array_key_exists('umuuid',$_COOKIE)){
            $umuuid = $this->my_uuid();
            setcookie('umuuid',$umuuid,time()+3600*24*30);
        }else{
            $umuuid = $_COOKIE['umuuid'];
        }

        $is_adcount = Db::name('adcount')->where('id',$id)->find();
        
        if($is_adcount){
            $accept  = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
            $webInfo = getWebInfo($_SERVER['HTTP_USER_AGENT'],$accept);
            $reIP    = getIP();//ip
            // $url     = IP_URL.$reIP;
            // $data    = http_url($url);
            $ip_obj = new Ip();
            $ipInfo = $ip_obj->find($reIP);
            // $ipInfo  = json_decode($data,true);
            //淘宝ip库格式
            // if($ipInfo['code'] == 0){
            //     $country = isset($ipInfo['data']['country']) ? $ipInfo['data']['country'] : '';//国家
            //     $region = isset($ipInfo['data']['region']) ? $ipInfo['data']['region'] : '';//省份
            //     $city = isset($ipInfo['data']['city']) ? $ipInfo['data']['city'] : '';//城市
            //     $isp = isset($ipInfo['data']['isp']) ? $ipInfo['data']['isp'] : '';//运营商
            // }

            //本地ip库格式
            if($ipInfo){
                $country = isset($ipInfo[0]) ? $ipInfo[0] : '';//国家
                $region = isset($ipInfo[1]) ? $ipInfo[1] : '';//省份
                $city = isset($ipInfo[2]) ? $ipInfo[2] : '';//城市
                $isp = '';//运营商
            }

            $data = [ 
                'cid'        => $id,
                'wid'        => $web_id,
                'system'     => $webInfo['system'],
                'equip'      => $webInfo['equip'],
                'browser'    => $webInfo['browser'],
                'lang'       => $webInfo['lang'],
                'country'    => $country,
                'province'   => $region,
                'city'       => $city,
                'isp'        => $isp,
                'count_ip'   => $reIP,
                'umuuid'     => $umuuid,
                'response'   => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',//受访域名
                'visit_time' => time()
            ];
            //测试
            // $data = [
            //     'cid' => $id,
            //     'wid' => $web_id,
            //     'country'=>'中国',
            //     'province'=>'广东',
            //     'city'=>'广州',
            //     'count_ip'=>$reIP,
            //     'visit_time'=>time()
            // ];
            
            if(!empty($code)){
                $wechat = get_wechat_num_qrcode3($code);
            }
            // dump($wechat);exit();
            $result = Db::name('count_detail_'.TIME_PREFIX)->insertGetId($data);
            if(!$result){
                echo $result->getLastSql();
            }else{
                //$.get('https://{$_SERVER['HTTP_HOST']}/api/change_wx/get_wechat_num_qrcode2',{code:'{$code}'});
                return $wechat."var width = window.screen.availWidth;var height  = window.screen.availHeight;var fbl = width+'x'+height;var a=encodeURIComponent,ref = document.referrer; $(function(){ $.get('{$this->request_url}/api/count/ref_stat.html?id={$id}&r='+a(ref)+'&umuuid={$umuuid}&uid={$result}&rp='+fbl);}); _sns = new Object();_sns.push = function(stxlwx,kwd){var data_str = {'WeName':stxlwx,'id':{$result},'keyword':kwd};$.post('{$this->request_url}/api/count/copyAction', data_str);};_sns.comp = function(siteid,compid){var data_str = {'siteid':siteid,'ip':'{$reIP}','compid':compid};$.get('{$this->request_url}/api/count/cli_complaint', data_str);};";
            }
        }
    }

    /**
     * @param int $id 
     * @return int 
     */
    public function setCookieUuid($id){
        $is_adcount = Db::name('adcount')->where('id',$id)->find();
        if(array_key_exists('UM_distinctid',$_COOKIE)){
            $umuuid = $_COOKIE['UM_distinctid'];
        }elseif(!array_key_exists('umuuid',$_COOKIE)){
            $umuuid = $this->my_uuid();
            setcookie('umuuid',$umuuid,time()+3600*24*30);
        }else{
            $umuuid = $_COOKIE['umuuid'];
        }
        if($is_adcount) return $umuuid;
    }


    /**
     * @param int $id
     * @param int $web_id
     * @param int $umuuid 
     * @param string $code 
     * @return array
     */
    public function saveUserInfo($id,$web_id,$umuuid){
        $reIP=getIP();//ip
        $url = IP_URL.$reIP;
        $data = http_url($url);
        $arr = explode('=',$data); 
        $abc = substr(trim($arr[1]),0,-1);
        $address = json_decode($abc,true);
        $data = [
            'cid' => $id,
            'wid' => $web_id,
            'country'=>$address['country'],
            'province'=>$address['province'],
            'city'=>$address['city'],
            'count_ip'=>$reIP,
            'umuuid'=>$umuuid,
            'response'=>isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
            'visit_time'=>time()
        ];

        //测试
        // $data = [
        //     'cid' => $id,
        //     'wid' => $web_id,
        //     'country'=>'中国',
        //     'province'=>'广东',
        //     'city'=>'广州',
        //     'count_ip'=>$reIP,
        //     'visit_time'=>time()
        // ];
        return $data;
    }


    //异步统计方法
    public function ajax_tj_stat($id,$web_id,$code = ''){
        $umuuid = self::setCookieUuid($id);
        if($umuuid){
            $data = self::saveUserInfo($id,$web_id,$umuuid);
            $wechat = '';
            if(!empty($code)){
                $wechat = ajaxGetWechatInfo($code);
            }
            $result = Db::name('count_detail_'.TIME_PREFIX)->insertGetId($data);

            if($result){
                $reIP = $data['count_ip'];
                return $wechat."var ref = document.referrer;$.get('{$this->request_url}/api/count/ref_stat.html?id={$id}&r='+encodeURIComponent(ref)+'&umuuid={$umuuid}&uid={$result}');_sns = new Object();_sns.push = function(stxlwx,kwd){var data_str = {'WeName':stxlwx,'id':{$result},'keyword':kwd};$.post('{$this->request_url}/api/count/copyAction', data_str);};_sns.comp = function(siteid,compid){var data_str = {'siteid':siteid,'ip':'{$reIP}','compid':compid};$.get('{$this->request_url}/api/count/cli_complaint', data_str);};";
            }
        }
        return false;
    }




    public function copyAction(){
        if($this->request->post()){
            $data = $this->request->post();
            $id = $data['id'];//当前访问过的id
            $wechat_name = $data['WeName'];
            $arr = [
                'is_copy'=>1,
                'copu_wechat'=>$wechat_name,
                'copy_time'=>time(),
            ];
            $keyword = isset($data['keyword']) ? urldecode($data['keyword']) : '';
            if(!empty($keyword)){
                $arr['origin_keyword'] = $keyword;
            }
            $result = Db::name('count_detail_'.TIME_PREFIX)->where('id',$id)->update($arr);
            if($result){
                $this->copyWechatNumber($wechat_name);
            }
            return json([$result]);
        }
    }

    public function copyWechatNumber($wechat=''){
        //查询wechatnum表数据
        // $wechat = 'dss346';
        $find_wechat = model('wechatnum')->where('wechat_name',$wechat)->find();
            if($find_wechat && $find_wechat['is_expire'] !== 0){
                if($find_wechat['warn_num'] < 10){
                    $map['copu_wechat'] = ['eq',$wechat];
                    $map['visit_time'] = ['between',[$find_wechat['start_time'],$find_wechat['end_time']]];
                    $copy_wechat = Db::name('count_detail_'.TIME_PREFIX)->where($map)->count();
                    // dump($testInfo['copy_num'].'sss'.$copy_wechat);exit();
                    if($find_wechat['set_copy'] < $copy_wechat){
                        $this->sendmail($wechat,$find_wechat);
                    }
                }elseif(time() > $find_wechat['end_time']){
                    model('wechatnum')->where('id',$find_wechat['id'])->update(['is_expire'=>0]);
                }
            }
    }
    
    
    public function sendmail($wechat,$find_wechat){
        $emails = explode(',',$find_wechat['email']);
        $smtpserver = "smtp.163.com";//SMTP服务器
        $smtpserverport =25;//SMTP服务器端口
        $smtpusermail = "qq2161811@163.com";//SMTP服务器的用户邮箱
        foreach($emails as $ve){
            $smtpemailto = $ve;//发送给谁
            $smtpuser = "qq2161811";//SMTP服务器的用户帐号，注：部分邮箱只需@前面的用户名
            $smtppass = "1234qwer";//SMTP服务器的用户密码
            $mailtitle = '微信号复制数超出通知';//邮件主题
            $mailcontent = "<h1>您户是 <span style='color:red;background-color:yellow;'>".$find_wechat['remark']."</span> 的微信号为 <span style='color:red;background-color:yellow;'>".$find_wechat['wechat_name']."</span> 已超过复制次数啦，赶快换掉吧</h1>";//邮件内容
            $mailtype = "HTML";//邮件格式（HTML/TXT）,TXT为文本邮件
            //************************ 配置信息 ****************************
            $smtp = new Smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证.
            $smtp->debug = false;//是否显示发送的调试信息
            $state = $smtp->sendmail($smtpemailto, $smtpusermail, $mailtitle, $mailcontent, $mailtype);
            // dump($state);
        }
        
        $this->updateWechatNum($find_wechat);
    }

    //修改警告数据
    public function updateWechatNum($find_wechat){
        // dump($find_wechat);exit();
        $data = [];
        if($find_wechat['is_warn'] == 1){
            $data['is_warn'] = 0;
            $data['warn_num'] = 1;
        }else{
            $data['warn_num'] = $find_wechat['warn_num']+1;
        }

        if(time() > $find_wechat['end_time']){
            $data['is_expire'] = 0;
        }

        model('wechatnum')->where('id',$find_wechat['id'])->update($data);
    }


    public function testcopyAction(){
        if($this->request->post()){
            $data = $this->request->post();
            $id = $data['id'];//当前访问过的id
            $wechat_name = $data['WeName'];
            $arr = [
                'is_copy'=>1,
                'copu_wechat'=>$wechat_name,
                'copy_time'=>time(),
            ];
            $keyword = isset($data['keyword']) ? urldecode($data['keyword']) : '';
            if(!empty($keyword)){
                $arr['origin_keyword'] = $keyword;
            }

            // $ref = $_SERVER['HTTP_REFERER'];
            // $header = getallheaders();
            // dump($header);

            // $data['origin_keyword'] = $ref;
            // $url_dec = urldecode($ref);
            // $pattern = "/&wo?r?d=([\s\S]+?)&/";
            // if(preg_match_all($pattern,$url_dec,$matches)){
                // $arr['origin_keyword'] = $matches[1];
            // }

            $result = Db::name('count_detail_'.TIME_PREFIX)->where('id',$id)->update($arr);
            if($result){
                $this->copyWechatNumber($wechat_name);
            }
            return json([$result]);
        }
    }


    /*
    根据素材id的页面的点击获取对应的来源url
    */
    public function getRefer()
    {
        // dump(TIME_PREFIX);exit();
        # code...
        if($this->request->post()){
            $data = $this->request->post();
            //  存储url到数据  fromurl
            $referurl = $data;
            //  写入数据  ref:http://review.e.qq.com/toutiao/jump/
            $ref = !empty($data['ref']) ? $data['ref'] : '';
            if(!empty($ref)){
                $arr['referer'] = $ref;
            }
            $result = Db::name('count_detail_'.TIME_PREFIX)->where('id',$data['id'])->update($arr);
            return json([$result]);
        }
    }

    public function cli_complaint($siteid,$compid,$ip){
        $address = $this->get_address($ip);
        $data = [
            'cid' => $siteid,
            'comp_id' => $compid,
            'comp_ip' => $ip,
            'country'=> $address['country'],
            'province'=> $address['province'],
            'city'=> $address['city'],
        ];
        $result = $this->complaint_model->allowField(true)->save($data);
        if($result){
            return json(['投诉成功']);
        }
    }

    public function get_address($ip){
        $url = IP_URL.$ip;
        $data = http_url($url);
        $arr = explode('=',$data); 
        $abc = substr(trim($arr[1]),0,-1);
        $address = json_decode($abc,true);
        return $address;
    }

}